
version 9.2

clear
set mem 300m
set more off

global foldp "C:/work/Wealth Counterfactuals/Verification/"


tempname name nobs p25nw p50nw p75nw ost p25st p50st p75st obus p25bus p50bus p75bus ohm p25hm p50hm p75hm omrt p25mrt p50mrt p75mrt


foreach cntr of numlist 0(1)12 {

   use "${foldp}Data/HRS/HRS_DG.dta", clear
   append using "${foldp}Data/SHARE/SHARE_DG.dta"
   append using "${foldp}Data/ELSA/ELSA_DG.dta"


keep if country==`cntr'

keep if head==1

keep if wgtach!=0

qui ge double secdebt = hmortv + hhmlov 
qui ge secdebto = (secdebt>0) if secdebt!=.

* Name
scalar `name' = `cntr'

* # of Obs
scalar `nobs' = _N

* Net Wealth
qui su hnetwv [w=wgtach], d
scalar `p25nw' = r(p25)
scalar `p50nw' = r(p50)
scalar `p75nw' = r(p75)


* Stocks
qui su hrfino [w=wgtach], d
scalar `ost' = r(mean) 

qui su hrfinv [w=wgtach] if hrfino==1, d
scalar `p25st' = r(p25)
scalar `p50st' = r(p50)
scalar `p75st' = r(p75)

* Business
qui su hownbo [w=wgtach], d
scalar `obus' = r(mean) 

qui su hownbv [w=wgtach] if hownbo==1, d
scalar `p25bus' = r(p25)
scalar `p50bus' = r(p50)
scalar `p75bus' = r(p75)

* Home
qui su hhomeo [w=wgtach], d
scalar `ohm' = r(mean) 

qui su hhomev [w=wgtach] if hhomeo==1, d
scalar `p25hm' = r(p25)
scalar `p50hm' = r(p50)
scalar `p75hm' = r(p75)

* Mortgage
qui su secdebto [w=wgtach], d
scalar `omrt' = r(mean) 

qui su secdebt [w=wgtach] if secdebto==1, d
scalar `p25mrt' = r(p25)
scalar `p50mrt' = r(p50)
scalar `p75mrt' = r(p75)


if `cntr' ==0 {
mat table = `name', `nobs', `p25nw', `p50nw', `p75nw', `ost', `p25st', `p50st', `p75st', `obus', `p25bus', `p50bus', `p75bus', `ohm', `p25hm', `p50hm', `p75hm', `omrt', `p25mrt', `p50mrt', `p75mrt'
}

 if `cntr' >0 {
mat tableh = `name', `nobs', `p25nw', `p50nw', `p75nw', `ost', `p25st', `p50st', `p75st', `obus', `p25bus', `p50bus', `p75bus', `ohm', `p25hm', `p50hm', `p75hm', `omrt', `p25mrt', `p50mrt', `p75mrt'
mat  table = table\tableh
}


if `cntr'==0 {

         foreach usreg of numlist 2 1 3 4 { 
         
         
	 * Name
         scalar `name' = `cntr'`usreg'
         
         * # of Obs
	 qui count if r7cenreg==`usreg'
         scalar `nobs' = r(N)

	 * Net Wealth
	 qui su hnetwv [w=wgtach] if r7cenreg==`usreg', d
	 scalar `p25nw' = r(p25)
	 scalar `p50nw' = r(p50)
	 scalar `p75nw' = r(p75)
	 
	 * Stocks
	 qui su hrfino [w=wgtach] if r7cenreg==`usreg', d
	 scalar `ost' = r(mean) 
	 
	 qui su hrfinv [w=wgtach] if hrfino==1 & r7cenreg==`usreg', d
	 scalar `p25st' = r(p25)
	 scalar `p50st' = r(p50)
	 scalar `p75st' = r(p75)
	 
	 * Business
	 qui su hownbo [w=wgtach] if r7cenreg==`usreg', d
	 scalar `obus' = r(mean) 
	 
	 qui su hownbv [w=wgtach] if hownbo==1 & r7cenreg==`usreg', d
	 scalar `p25bus' = r(p25)
	 scalar `p50bus' = r(p50)
	 scalar `p75bus' = r(p75)
	 
	 * Home
	 qui su hhomeo [w=wgtach] if r7cenreg==`usreg', d
	 scalar `ohm' = r(mean) 
	 
	 qui su hhomev [w=wgtach] if hhomeo==1 & r7cenreg==`usreg', d
	 scalar `p25hm' = r(p25)
	 scalar `p50hm' = r(p50)
         scalar `p75hm' = r(p75)
         
         * Mortgage     
         qui su secdebto [w=wgtach] if r7cenreg==`usreg', d
         scalar `omrt' = r(mean) 
      
         qui su secdebt [w=wgtach] if secdebto==1 & r7cenreg==`usreg', d
         scalar `p25mrt' = r(p25)
         scalar `p50mrt' = r(p50)
         scalar `p75mrt' = r(p75)
      
      mat tableh = `name', `nobs', `p25nw', `p50nw', `p75nw', `ost', `p25st', `p50st', `p75st', `obus', `p25bus', `p50bus', `p75bus', `ohm', `p25hm', `p50hm', `p75hm', `omrt', `p25mrt', `p50mrt', `p75mrt'
      mat  table = table\tableh
         }

      }
   
   
  }
  
  use "${foldp}Data/SHARE/SHARE_DG.dta", clear
  append using "${foldp}Data/ELSA/ELSA_DG.dta"
 
 
  keep if head==1
  
qui ge double secdebt = hmortv + hhmlov 
qui ge secdebto = (secdebt>0) if secdebt!=.
  
  * Name
  scalar `name' = 13
  
  * # of Obs
  scalar `nobs' = _N
  
  * Net Wealth
  qui su hnetwv [w=wgtach], d
  scalar `p25nw' = r(p25)
  scalar `p50nw' = r(p50)
  scalar `p75nw' = r(p75)
  
  
  * Stocks
  qui su hrfino [w=wgtach], d
  scalar `ost' = r(mean) 
  
  qui su hrfinv [w=wgtach] if hrfino==1, d
  scalar `p25st' = r(p25)
  scalar `p50st' = r(p50)
  scalar `p75st' = r(p75)
  
  * Business
  qui su hownbo [w=wgtach], d
  scalar `obus' = r(mean) 
  
  qui su hownbv [w=wgtach] if hownbo==1, d
  scalar `p25bus' = r(p25)
  scalar `p50bus' = r(p50)
  scalar `p75bus' = r(p75)
  
  * Home
  qui su hhomeo [w=wgtach], d
  scalar `ohm' = r(mean) 
  
  qui su hhomev [w=wgtach] if hhomeo==1, d
  scalar `p25hm' = r(p25)
  scalar `p50hm' = r(p50)
  scalar `p75hm' = r(p75)
  
  *Mortgage
  qui su secdebto [w=wgtach], d
  scalar `omrt' = r(mean) 
  
  qui su secdebt [w=wgtach] if secdebto==1, d
  scalar `p25mrt' = r(p25)
  scalar `p50mrt' = r(p50)
  scalar `p75mrt' = r(p75)

  
  mat tableh = `name', `nobs', `p25nw', `p50nw', `p75nw', `ost', `p25st', `p50st', `p75st', `obus', `p25bus', `p50bus', `p75bus', `ohm', `p25hm', `p50hm', `p75hm',  `omrt', `p25mrt', `p50mrt', `p75mrt'
  mat  table = table\tableh


 ************************************************************************************************************************************************
 
 
 matrix coln table= Country Obs NW_25 NW_50 NW_75 Own_ST ST_25 ST_50 ST_75 Own_BUS BUS_25 BUS_50 BUS_75 Own_HM HM_25 HM_50 HM_75 Own_MRT MRT_25 MRT_50 MRT_75
  
 mat2txt, matrix(table) saving(${foldp}/Results/DG/Sum_stats/Table1) title(Asset Ownership Rates and Levels) format(%15.3f) replace

   
   
   

